const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载 
   */
  onLoad: function (options) {
    if (options.scene) {
      let scene = decodeURIComponent(options.scene);
      if (scene) {
        let info_arr = [];
        info_arr = scene.split(",");
        this.data.RId = info_arr[0];
        this.data.CAT = info_arr[1];
        this.data.STAT = info_arr[2];
        this.data.REC = info_arr[3];
        app._setMid(info_arr[4]);
      }
      // if (scene) {
      //   let info_arr = [];
      //   info_arr = scene.split(",");
      //   for (let i = 0; i < info_arr.length; i++) {
      //     let chil_arr = [];
      //     chil_arr = info_arr[i].split("=");
      //     if (chil_arr[0] == "RId") {
      //       this.data.RId = chil_arr[1];
      //     } else if (chil_arr[0] == "CAT") {
      //       this.data.CAT = chil_arr[1];
      //     } else if (chil_arr[0] == "STAT") {
      //       this.data.STAT = chil_arr[1];
      //     } else if (chil_arr[0] == "REC") {
      //       this.data.REC = chil_arr[1];
      //     } else if (chil_arr[0] == "mid") {
      //       app._setMid(chil_arr[1]);
      //     }
      //   }
      // }
    } else {
      if (options.mid) {
        app._setMid(options.mid);
      }
      let {CAT,STAT,REC,RId} = options;
      this.data.RId = RId;
      this.data.CAT = CAT||'';
      this.data.STAT = STAT||'';
      this.data.REC = REC||'';
    }
    this.checkLogin();//验证是否登录
  },
  checkLogin() {
    let url = app.getNetAddresss("member.login.check-login");
    app._getNetWork({
      url: url,
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          let _url = app.globalData.host + `/addons/yun_shop/?menu#/shareRoom/player?i=` + app.globalData.uniacid;
          _url = `${_url}&RId=${this.data.RId}&CAT=${this.data.CAT}&STAT=${this.data.STAT}&REC=${this.data.REC}`;
          let wx_token = wx.getStorageSync('wx_token');
          _url = `${_url}&min_token=${wx_token}`;//自营商城免登录
          this.setData({
            link: _url
          })
        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },

  h5Method(e){
    console.log('bindmessage:::',e)
    let arr = e.detail.data;
    let obj = null;
    arr.forEach(element => {
      if(element.mini_url && element.murl){
        obj = element
      }
    });
    if(obj){
      wx.setStorageSync('H5PayCallBackUrl', obj)
      wx.navigateTo({
        url: obj.murl,
      })
      return  
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  onShareTimeline(){
    return{
      query: `RId=${this.data.RId}&CAT=${this.data.CAT}&STAT=${this.data.STAT}&REC=${this.data.REC}`
    };
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: `/mircoApp/share-room/player/player?RId=${this.data.RId}&CAT=${this.data.CAT}&STAT=${this.data.STAT}&REC=${this.data.REC}`
    }
  }
});